import { mapState, createNamespacedHelpers } from 'vuex'
import { useStateMapper } from './useMapper'
import { checkType } from './index'

export function useState(moduleName, mapper) {
  let mapperFn = mapState
  if (checkType(moduleName) === '[object String]' && moduleName.length > 0) {
    mapperFn = createNamespacedHelpers(moduleName).mapState
  }
  return useStateMapper(mapper, mapperFn)
}
